package leecode

func isSubStructure(A *TreeNode, B *TreeNode) bool {
	if A == nil || B == nil {
		return false
	}
	leftA := isSubStructure(A.Left, B)
	leftB := isSubStructure(A.Right, B)
	return helper(A, B) || leftA || leftB
}

func helper(A, B *TreeNode) bool {
	//B查找完毕
	if B == nil {
		return true
	}
	if A == nil || (A.Val != B.Val) {
		return false
	}
	return helper(A.Left, B.Left) && helper(A.Right, B.Right)
}
